﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Waker.Common;

namespace Waker.Cards
{
    public partial class FormDoorPerssion : Base.FormBaseToolBar
    {
        public FormDoorPerssion()
        {
            InitializeComponent();
        }

        private void FormDoorPerssion_Load(object sender, EventArgs e)
        {
            var dt = new BAL.BAL_Device().GetAllDeviceIDAndName();
            ControlUtil.FillImageComboBox(dt, icbDevice, "Device_Name", "Device_ID");
            icbDevice.SelectedIndex = 0;

            var dtSite = new BAL.BAL_Cards().GetAllDepartment();
            ckbListSubContractor.Properties.DataSource = dtSite;
            FormRefresh();
        }
        public override void FormRefresh()
        {
            if (icbDevice.EditValue == null || icbDevice.EditValue == DBNull.Value || string.IsNullOrEmpty(icbDevice.EditValue.ToString()))
            {
                UI.ShowError("请选择门禁设备");
                return;
            }
            var dt = new BAL.BAL_Cards().GetDoorPerssion(icbDevice.EditValue.ToString()
                   , ckbListSubContractor.EditValue == null ? string.Empty : ckbListSubContractor.EditValue.ToString().Trim()
                , txtEmp_Name.Text.Trim()
                , txtEmp_No.Text.Trim()
                , txtEmp_IDCard.Text.Trim()
                );
            this.gridControl1.DataSource = dt;
            if (gridView1.GroupCount > 0)
                gridView1.ExpandGroupRow(gridView1.FocusedRowHandle, true);
        }

        private void barBtn1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var f = new FormDoorPerssionEdit();
            f.ShowDialog();
            FormRefresh();
        }
    }
}
